var ns, toast,imageBrowser;
var app = new Vue({
    el: '#app',
    data: {
        form: {
            id: 0,
            title: '',
            tag: '',
            time: '',
            content: '',
            type:1//1--新闻
        }
    },
    methods: {
        get_data: function() {
            var that = this;
            var options = {};
            if(that.form.type==1){
                options.id = that.form.id;
                options.action = 'getcommunitynewsdetails';
                ns.post(options, function(succeed, data, err) {
                    console.log(JSON.stringify(data));
                    if (succeed) {
                        that.form.title = data.Title;
                        that.form.content = data.Content;
                    } else if (err) {
                        api.toast({
                            msg: err,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                }, { toast: true });
            }else{
                options.id = that.form.id;
                options.action = 'getwuyegonggaodetail';
                ns.post(options, function(succeed, data, err) {
                    console.log(JSON.stringify(data));
                    if (succeed) {
                        that.form = data;
                    } else if (err) {
                        api.toast({
                            msg: err,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                }, { toast: true });

            }
            
        },
        img_browser: function(imgurl) {
            var that = this;
            var imgurls = [];
            imgurls.push(imgurl);
            imageBrowser.openImages({
                imageUrls: imgurls,
                showList: false,
                activeIndex: 0
            });
        },
        save_read: function() {
            var that = this;
            var options = {};
            options.type = 1;
            options.deviceid = api.deviceId;
            options.id = that.form.id;
            options.action = 'saveusermsg';
            ns.post(options, function(succeed, data, err) {
                api.sendEvent({
                    name: 'savereadingpagecomplete'
                });
            });
        }
    }
});
apiready = function() {
    api.parseTapmode();
    imageBrowser = api.require('imageBrowser');
    ns = window.Foresight.Util;
    toast = new auiToast();
    app.form.id = api.pageParam.id || 0;
    app.form.type = api.pageParam.type;
    console.log(JSON.stringify(app.form.type));
    app.get_data();
    app.save_read();
    //点击查看图片
    setTimeout(function () {
        var imageshow = document.getElementsByTagName('img');
        for (var i = 0; i < imageshow.length; i++) {
            imageshow[i].onclick = function (ret) {
                app.img_browser(this.src);
            }
        }
    }, 500);
}
